package cn.iocoder.yudao.module.bpm.framework.flowable.core.listener.demo.exection;

import cn.hutool.core.util.ObjectUtil;
import io.reactivex.rxjava3.core.Completable;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
import org.flowable.task.api.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 类型为 class 的 ExecutionListener 监听器示例
 *
 * @author 芋道源码
 */
@Slf4j
@Component
public class DemoDelegateClassExecutionListener implements JavaDelegate {

    /**
     * @Description: 审批人为空测试
     * @Author: 雨同我
     * @DateTime: 2024/8/19 17:45
     * @param: null:
     * @return:
    */

    @Autowired
    private TaskService taskService;

    @Override
    public void execute(DelegateExecution execution) {
//        Task task = taskService.createTaskQuery().executionId(execution.getId()).singleResult();
//        if (ObjectUtil.isNotEmpty(task)){
//            taskService.complete(task.getId());
//        }else {
//            System.out.println(task+"=================");
//        }

        log.info("[execute][execution({}) 被调用！变量有：{}]", execution.getId(),
                execution.getCurrentFlowableListener().getFieldExtensions());
    }
}